﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace ReloadSite
{
    public class WebScraper
    {
        private HttpClient _httpClient = null;

        public async Task<string> GetPageContentAsync(string url)
        {
            try
            {
                var handler = new HttpClientHandler
                {
                    ServerCertificateCustomValidationCallback = (sender, cert, chain, errors) =>
                    {
                        // 接受所有证书（不推荐用于生产环境）
                        return true;
                    }
                };
                _httpClient = new HttpClient(handler);
                _httpClient.Timeout = TimeSpan.FromMinutes(2);
                HttpResponseMessage response = await _httpClient.GetAsync(url);
                response.EnsureSuccessStatusCode();
                return await response.Content.ReadAsStringAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"获取网页内容失败: {ex.Message}");
                return null;
            }
        } 
    }
}
